package 操作系统实验.实验三.第二版;/**
 * ************************************************************************
 * 项目名称: projectweb <br>
 * 文件名称:  <br>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br>
 * 文件创建：1913040634刘世锦  <br>
 * 创建时间: 2021/4/20 <br>
 *
 * @version v1.0 <br>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br>
 * ************************************************************************
 */

/**
 * @ProjectName: projectweb
 * @ClassName: Processes
 * @Description: 请描述该类的功能
 * @Author: 1913040634刘世锦
 * @Date: 2021/4/20 12:49 .
 * @version v1.0
 */
import java.util.Scanner;

public class Processes {
    private String[] resourceName;    //系统资源名称
    private Integer[][] maxNum;       //Pi的需求资源数量（最大需求资源数量）
    private Integer[][] allocation;   //已分配给该进程的资源
    private Integer[][] needNum;      //还需要的资源数量
    private Integer AVAILABLE_COUNT_Y;//资源的种类数量
    private Integer PROCESSES_COUNT;  //进程的个数
    public Processes() {
        Init();
    }

    public Integer getAVAILABLE_COUNT_Y() {
        return AVAILABLE_COUNT_Y;
    }

    public void setAVAILABLE_COUNT_Y(Integer AVAILABLE_COUNT_Y) {
        this.AVAILABLE_COUNT_Y = AVAILABLE_COUNT_Y;
    }

    public Integer getPROCESSES_COUNT() {
        return PROCESSES_COUNT;
    }

    public void setPROCESSES_COUNT(Integer PROCESSES_COUNT) {
        this.PROCESSES_COUNT = PROCESSES_COUNT;
    }

    public String getResourceName(int j) {
        return resourceName[j];
    }

    public void setResourceName(String[] resourceName) {
        this.resourceName = resourceName;
    }

    public Integer[][] getMaxNum() {
        return maxNum;
    }

    public void setMaxNum(Integer[][] maxNum) {
        this.maxNum = maxNum;
    }

    public Integer getAllocation(int i,int j) {
        return allocation[i][j];
    }

    public void setAllocation(int i,int j,Integer allo) {
        allocation[i][j] = allo;
    }

    public Integer getNeedNum(int i,int j) {
        return needNum[i][j];
    }

    public void setNeedNum(int i,int j,Integer need) {
        needNum[i][j] = need;
    }

    /**
     * 初始化
     */
    public void Init() {
        System.out.print("请输入资源的种类数量：");
        Scanner input = new Scanner(System.in);
        AVAILABLE_COUNT_Y = input.nextInt();
        resourceName = new String[AVAILABLE_COUNT_Y];
        System.out.println("请输入各类资源的名称：");
        for (int i = 0; i < AVAILABLE_COUNT_Y; i++) {
            System.out.print("资源" + (i+1) + "的名称：");
            resourceName[i] = input.next();
        }

        System.out.println("请输入进程的个数：");
        PROCESSES_COUNT = input.nextInt();
        maxNum = new Integer[PROCESSES_COUNT][AVAILABLE_COUNT_Y];
        allocation = new Integer[PROCESSES_COUNT][AVAILABLE_COUNT_Y];
        needNum = new Integer[PROCESSES_COUNT][AVAILABLE_COUNT_Y];
        for (int i = 0; i < PROCESSES_COUNT; i++) {
            System.out.println("请输入进程" + (i+1) + "对" + AVAILABLE_COUNT_Y + "类资源的最大需求：");
            for (int j = 0; j < AVAILABLE_COUNT_Y; j++) {
                System.out.print(resourceName[j] + "：");
                maxNum[i][j] = input.nextInt();
            }

            System.out.println("请输入进程" + (i+1) + "已申请到的各类资源数：");
            for (int j = 0; j < AVAILABLE_COUNT_Y; j++) {
                System.out.print(resourceName[j] + "：");
                allocation[i][j] = input.nextInt();
            }

            for (int j = 0; j < AVAILABLE_COUNT_Y; j++) {
                needNum[i][j] = maxNum[i][j] - allocation[i][j];
            }

        }
    }
}

